﻿Imports System.Data.OleDb

Partial Class admin_AdminProducts
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Dim accessCon As New OleDbConnection(ConfigurationManager.ConnectionStrings("GotPinkDB").ConnectionString)
        accessCon.Open()

        If fupImageBrowser.HasFile Then

            fupImageBrowser.SaveAs(MapPath("~\Images\products\" + fupImageBrowser.FileName))
        End If

        Dim sql As String = "INSERT INTO Products (ProductName, ProductDesc, Amount, IsVisible, ImagePath, CanPersonalize) VALUES (@ProdName, @ProdDesc, @ProdAmount, @ProdIsVisible, @ProdImagePath, @CanPersonalize)"
        Dim cmd As New OleDbCommand(sql, accessCon)
        Try
            cmd.Parameters.AddWithValue("@ProdName", txtName.Text)
            cmd.Parameters.AddWithValue("@ProdDesc", txtDescription.Text)
            cmd.Parameters.AddWithValue("@ProdAmount", txtAmount.Text)
            cmd.Parameters.AddWithValue("@ProdIsVisible", chkIsVisible.Checked)
            cmd.Parameters.AddWithValue("@ProdImagePath", "~\Images\products\" & fupImageBrowser.FileName.ToString)
            cmd.Parameters.AddWithValue("@CanPersonalize", chkPersonlize.Checked)
            cmd.ExecuteNonQuery()
        Catch ex As Exception

        Finally
            cmd.Dispose()
            accessCon.Close()
        End Try
        ClearProducts()
        ajxModalPopup.Show()


    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ClearProducts()
        ajxModalPopup.Show()
    End Sub

    Protected Sub btnDone_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDone.Click
        ajxModalPopup.Hide()
        grvProducts.DataBind()
    End Sub

    Sub ClearProducts()
        txtName.Text = ""
        txtDescription.Text = ""
        txtAmount.Text = ""
        chkIsVisible.Checked = True
    End Sub

End Class
